home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / RTNETLIN.{8S < prev    next >
Text File  |  1999-09-17  |  16KB  |  668 lines

  1. #ifndef __LINUX_RTNETLINK_H
  2. #define __LINUX_RTNETLINK_H
  3.  
  4. #include <linux/config.h>
  5. #include <linux/netlink.h>
  6.  
  7. #define RTNL_DEBUG 1
  8.  
  9.  
  10. /****
  11.  *        Routing/neighbour discovery messages.
  12.  ****/
  13.  
  14. /* Types of messages */
  15.  
  16. #define RTM_BASE    0x10
  17.  
  18. #define    RTM_NEWLINK    (RTM_BASE+0)
  19. #define    RTM_DELLINK    (RTM_BASE+1)
  20. #define    RTM_GETLINK    (RTM_BASE+2)
  21.  
  22. #define    RTM_NEWADDR    (RTM_BASE+4)
  23. #define    RTM_DELADDR    (RTM_BASE+5)
  24. #define    RTM_GETADDR    (RTM_BASE+6)
  25.  
  26. #define    RTM_NEWROUTE    (RTM_BASE+8)
  27. #define    RTM_DELROUTE    (RTM_BASE+9)
  28. #define    RTM_GETROUTE    (RTM_BASE+10)
  29.  
  30. #define    RTM_NEWNEIGH    (RTM_BASE+12)
  31. #define    RTM_DELNEIGH    (RTM_BASE+13)
  32. #define    RTM_GETNEIGH    (RTM_BASE+14)
  33.  
  34. #define    RTM_NEWRULE    (RTM_BASE+16)
  35. #define    RTM_DELRULE    (RTM_BASE+17)
  36. #define    RTM_GETRULE    (RTM_BASE+18)
  37.  
  38. #define    RTM_NEWQDISC    (RTM_BASE+20)
  39. #define    RTM_DELQDISC    (RTM_BASE+21)
  40. #define    RTM_GETQDISC    (RTM_BASE+22)
  41.  
  42. #define    RTM_NEWTCLASS    (RTM_BASE+24)
  43. #define    RTM_DELTCLASS    (RTM_BASE+25)
  44. #define    RTM_GETTCLASS    (RTM_BASE+26)
  45.  
  46. #define    RTM_NEWTFILTER    (RTM_BASE+28)
  47. #define    RTM_DELTFILTER    (RTM_BASE+29)
  48. #define    RTM_GETTFILTER    (RTM_BASE+30)
  49.  
  50. #define    RTM_MAX        (RTM_BASE+31)
  51.  
  52. /* 
  53.    Generic structure for encapsulation optional route information.
  54.    It is reminiscent of sockaddr, but with sa_family replaced
  55.    with attribute type.
  56.  */
  57.  
  58. struct rtattr
  59. {
  60.     unsigned short    rta_len;
  61.     unsigned short    rta_type;
  62. };
  63.  
  64. /* Macros to handle rtattributes */
  65.  
  66. #define RTA_ALIGNTO    4
  67. #define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) )
  68. #define RTA_OK(rta,len) ((len) > 0 && (rta)->rta_len >= sizeof(struct rtattr) && \
  69.              (rta)->rta_len <= (len))
  70. #define RTA_NEXT(rta,attrlen)    ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
  71.                  (struct rtattr*)(((char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
  72. #define RTA_LENGTH(len)    (RTA_ALIGN(sizeof(struct rtattr)) + (len))
  73. #define RTA_SPACE(len)    RTA_ALIGN(RTA_LENGTH(len))
  74. #define RTA_DATA(rta)   ((void*)(((char*)(rta)) + RTA_LENGTH(0)))
  75. #define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
  76.  
  77.  
  78.  
  79.  
  80. /******************************************************************************
  81.  *        Definitions used in routing table administation.
  82.  ****/
  83.  
  84. struct rtmsg
  85. {
  86.     unsigned char        rtm_family;
  87.     unsigned char        rtm_dst_len;
  88.     unsigned char        rtm_src_len;
  89.     unsigned char        rtm_tos;
  90.  
  91.     unsigned char        rtm_table;    /* Routing table id */
  92.     unsigned char        rtm_protocol;    /* Routing protocol; see below    */
  93.     unsigned char        rtm_scope;    /* See below */    
  94.     unsigned char        rtm_type;    /* See below    */
  95.  
  96.     unsigned        rtm_flags;
  97. };
  98.  
  99. /* rtm_type */
  100.  
  101. enum
  102. {
  103.     RTN_UNSPEC,
  104.     RTN_UNICAST,        /* Gateway or direct route    */
  105.     RTN_LOCAL,        /* Accept locally        */
  106.     RTN_BROADCAST,        /* Accept locally as broadcast,
  107.                    send as broadcast */
  108.     RTN_ANYCAST,        /* Accept locally as broadcast,
  109.                    but send as unicast */
  110.     RTN_MULTICAST,        /* Multicast route        */
  111.     RTN_BLACKHOLE,        /* Drop                */
  112.     RTN_UNREACHABLE,    /* Destination is unreachable   */
  113.     RTN_PROHIBIT,        /* Administratively prohibited    */
  114.     RTN_THROW,        /* Not in this table        */
  115.     RTN_NAT,        /* Translate this address    */
  116.     RTN_XRESOLVE,        /* Use external resolver    */
  117. };
  118.  
  119. #define RTN_MAX RTN_XRESOLVE
  120.  
  121.  
  122. /* rtm_protocol */
  123.  
  124. #define RTPROT_UNSPEC    0
  125. #define RTPROT_REDIRECT    1    /* Route installed by ICMP redirects;
  126.                    not used by current IPv4 */
  127. #define RTPROT_KERNEL    2    /* Route installed by kernel        */
  128. #define RTPROT_BOOT    3    /* Route installed during boot        */
  129. #define RTPROT_STATIC    4    /* Route installed by administrator    */
  130.  
  131. /* Values of protocol >= RTPROT_STATIC are not interpreted by kernel;
  132.    they just passed from user and back as is.
  133.    It will be used by hypothetical multiple routing daemons.
  134.    Note that protocol values should be standardized in order to
  135.    avoid conflicts.
  136.  */
  137.  
  138. #define RTPROT_GATED    8    /* Apparently, GateD */
  139. #define RTPROT_RA    9    /* RDISC/ND router advertisments */
  140. #define RTPROT_MRT    10    /* Merit MRT */
  141. #define RTPROT_ZEBRA    11    /* Zebra */
  142. #define RTPROT_BIRD    12    /* BIRD */
  143.  
  144. /* rtm_scope
  145.  
  146.    Really it is not scope, but sort of distance to the destination.
  147.    NOWHERE are reserved for not existing destinations, HOST is our
  148.    local addresses, LINK are destinations, located on directly attached
  149.    link and UNIVERSE is everywhere in the Universe.
  150.  
  151.    Intermediate values are also possible f.e. interior routes
  152.    could be assigned a value between UNIVERSE and LINK.
  153. */
  154.  
  155. enum rt_scope_t
  156. {
  157.     RT_SCOPE_UNIVERSE=0,
  158. /* User defined values  */
  159.     RT_SCOPE_SITE=200,
  160.     RT_SCOPE_LINK=253,
  161.     RT_SCOPE_HOST=254,
  162.     RT_SCOPE_NOWHERE=255
  163. };
  164.  
  165. /* rtm_flags */
  166.  
  167. #define RTM_F_NOTIFY        0x100    /* Notify user of route change    */
  168. #define RTM_F_CLONED        0x200    /* This route is cloned        */
  169. #define RTM_F_EQUALIZE        0x400    /* Multipath equalizer: NI    */
  170.  
  171. /* Reserved table identifiers */
  172.  
  173. enum rt_class_t
  174. {
  175.     RT_TABLE_UNSPEC=0,
  176. /* User defined values */
  177.     RT_TABLE_DEFAULT=253,
  178.     RT_TABLE_MAIN=254,
  179.     RT_TABLE_LOCAL=255
  180. };
  181. #define RT_TABLE_MAX RT_TABLE_LOCAL
  182.  
  183.  
  184.  
  185. /* Routing message attributes */
  186.  
  187. enum rtattr_type_t
  188. {
  189.     RTA_UNSPEC,
  190.     RTA_DST,
  191.     RTA_SRC,
  192.     RTA_IIF,
  193.     RTA_OIF,
  194.     RTA_GATEWAY,
  195.     RTA_PRIORITY,
  196.     RTA_PREFSRC,
  197.     RTA_METRICS,
  198.     RTA_MULTIPATH,
  199.     RTA_PROTOINFO,
  200.     RTA_FLOW,
  201.     RTA_CACHEINFO
  202. };
  203.  
  204. #define RTA_MAX RTA_CACHEINFO
  205.  
  206. #define RTM_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
  207. #define RTM_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct rtmsg))
  208.  
  209. /* RTM_MULTIPATH --- array of struct rtnexthop.
  210.  *
  211.  * "struct rtnexthop" describres all necessary nexthop information,
  212.  * i.e. parameters of path to a destination via this nextop.
  213.  *
  214.  * At the moment it is impossible to set different prefsrc, mtu, window
  215.  * and rtt for different paths from multipath.
  216.  */
  217.  
  218. struct rtnexthop
  219. {
  220.     unsigned short        rtnh_len;
  221.     unsigned char        rtnh_flags;
  222.     unsigned char        rtnh_hops;
  223.     int            rtnh_ifindex;
  224. };
  225.  
  226. /* rtnh_flags */
  227.  
  228. #define RTNH_F_DEAD        1    /* Nexthop is dead (used by multipath)    */
  229. #define RTNH_F_PERVASIVE    2    /* Do recursive gateway lookup    */
  230. #define RTNH_F_ONLINK        4    /* Gateway is forced on link    */
  231.  
  232. /* Macros to handle hexthops */
  233.  
  234. #define RTNH_ALIGNTO    4
  235. #define RTNH_ALIGN(len) ( ((len)+RTNH_ALIGNTO-1) & ~(RTNH_ALIGNTO-1) )
  236. #define RTNH_OK(rtnh,len) ((rtnh)->rtnh_len >= sizeof(struct rtnexthop) && \
  237.                ((int)(rtnh)->rtnh_len) <= (len))
  238. #define RTNH_NEXT(rtnh)    ((struct rtnexthop*)(((char*)(rtnh)) + RTNH_ALIGN((rtnh)->rtnh_len)))
  239. #define RTNH_LENGTH(len) (RTNH_ALIGN(sizeof(struct rtnexthop)) + (len))
  240. #define RTNH_SPACE(len)    RTNH_ALIGN(RTNH_LENGTH(len))
  241. #define RTNH_DATA(rtnh)   ((struct rtattr*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
  242.  
  243. /* RTM_CACHEINFO */
  244.  
  245. struct rta_cacheinfo
  246. {
  247.     __u32    rta_clntref;
  248.     __u32    rta_lastuse;
  249.     __s32    rta_expires;
  250.     __u32    rta_error;
  251.     __u32    rta_used;
  252. };
  253.  
  254. /* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
  255.  
  256. enum
  257. {
  258.     RTAX_UNSPEC,
  259.     RTAX_LOCK,
  260.     RTAX_MTU,
  261.     RTAX_WINDOW,
  262.     RTAX_RTT,
  263.     RTAX_HOPS,
  264.     RTAX_SSTHRESH,
  265.     RTAX_CWND,
  266. };
  267.  
  268. #define RTAX_MAX RTAX_CWND
  269.  
  270.  
  271.  
  272. /*********************************************************
  273.  *        Interface address.
  274.  ****/
  275.  
  276. struct ifaddrmsg
  277. {
  278.     unsigned char    ifa_family;
  279.     unsigned char    ifa_prefixlen;    /* The prefix length        */
  280.     unsigned char    ifa_flags;    /* Flags            */
  281.     unsigned char    ifa_scope;    /* See above            */
  282.     int        ifa_index;    /* Link index            */
  283. };
  284.  
  285. enum
  286. {
  287.     IFA_UNSPEC,
  288.     IFA_ADDRESS,
  289.     IFA_LOCAL,
  290.     IFA_LABEL,
  291.     IFA_BROADCAST,
  292.     IFA_ANYCAST,
  293.     IFA_CACHEINFO
  294. };
  295.  
  296. #define IFA_MAX IFA_CACHEINFO
  297.  
  298. /* ifa_flags */
  299.  
  300. #define IFA_F_SECONDARY        0x01
  301.  
  302. #define IFA_F_DEPRECATED    0x20
  303. #define IFA_F_TENTATIVE        0x40
  304. #define IFA_F_PERMANENT        0x80
  305.  
  306. struct ifa_cacheinfo
  307. {
  308.     __s32    ifa_prefered;
  309.     __s32    ifa_valid;
  310. };
  311.  
  312.  
  313. #define IFA_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
  314. #define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
  315.  
  316. /*
  317.    Important comment:
  318.    IFA_ADDRESS is prefix address, rather than local interface address.
  319.    It makes no difference for normally configured broadcast interfaces,
  320.    but for point-to-point IFA_ADDRESS is DESTINATION address,
  321.    local address is supplied in IFA_LOCAL attribute.
  322.  */
  323.  
  324. /**************************************************************
  325.  *        Neighbour discovery.
  326.  ****/
  327.  
  328. struct ndmsg
  329. {
  330.     unsigned char    ndm_family;
  331.     unsigned char    ndm_pad1;
  332.     unsigned short    ndm_pad2;
  333.     int        ndm_ifindex;    /* Link index            */
  334.     __u16        ndm_state;
  335.     __u8        ndm_flags;
  336.     __u8        ndm_type;
  337. };
  338.  
  339. enum
  340. {
  341.     NDA_UNSPEC,
  342.     NDA_DST,
  343.     NDA_LLADDR,
  344.     NDA_CACHEINFO
  345. };
  346.  
  347. #define NDA_MAX NDA_CACHEINFO
  348.  
  349. #define NDA_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
  350. #define NDA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndmsg))
  351.  
  352. /*
  353.  *    Neighbor Cache Entry Flags
  354.  */
  355.  
  356. #define NTF_PROXY    0x08    /* == ATF_PUBL */
  357. #define NTF_ROUTER    0x80
  358.  
  359. /*
  360.  *    Neighbor Cache Entry States.
  361.  */
  362.  
  363. #define NUD_INCOMPLETE    0x01
  364. #define NUD_REACHABLE    0x02
  365. #define NUD_STALE    0x04
  366. #define NUD_DELAY    0x08
  367. #define NUD_PROBE    0x10
  368. #define NUD_FAILED    0x20
  369.  
  370. /* Dummy states */
  371. #define NUD_NOARP    0x40
  372. #define NUD_PERMANENT    0x80
  373. #define NUD_NONE    0x00
  374.  
  375.  
  376. struct nda_cacheinfo
  377. {
  378.     __u32        ndm_confirmed;
  379.     __u32        ndm_used;
  380.     __u32        ndm_updated;
  381.     __u32        ndm_refcnt;
  382. };
  383.  
  384. /****
  385.  *        General form of address family dependent message.
  386.  ****/
  387.  
  388. struct rtgenmsg
  389. {
  390.     unsigned char        rtgen_family;
  391. };
  392.  
  393. /*****************************************************************
  394.  *        Link layer specific messages.
  395.  ****/
  396.  
  397. /* struct ifinfomsg
  398.  * passes link level specific information, not dependent
  399.  * on network protocol.
  400.  */
  401.  
  402. struct ifinfomsg
  403. {
  404.     unsigned char    ifi_family;
  405.     unsigned char    __ifi_pad;
  406.     unsigned short    ifi_type;        /* ARPHRD_* */
  407.     int        ifi_index;        /* Link index    */
  408.     unsigned    ifi_flags;        /* IFF_* flags    */
  409.     unsigned    ifi_change;        /* IFF_* change mask */
  410. };
  411.  
  412. enum
  413. {
  414.     IFLA_UNSPEC,
  415.     IFLA_ADDRESS,
  416.     IFLA_BROADCAST,
  417.     IFLA_IFNAME,
  418.     IFLA_MTU,
  419.     IFLA_LINK,
  420.     IFLA_QDISC,
  421.     IFLA_STATS
  422. };
  423.  
  424.  
  425. #define IFLA_MAX IFLA_STATS
  426.  
  427. #define IFLA_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
  428. #define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
  429.  
  430. /* ifi_flags.
  431.  
  432.    IFF_* flags.
  433.  
  434.    The only change is:
  435.    IFF_LOOPBACK, IFF_BROADCAST and IFF_POINTOPOINT are
  436.    more not changeable by user. They describe link media
  437.    characteristics and set by device driver.
  438.  
  439.    Comments:
  440.    - Combination IFF_BROADCAST|IFF_POINTOPOINT is invalid
  441.    - If neiher of these three flags are set;
  442.      the interface is NBMA.
  443.  
  444.    - IFF_MULTICAST does not mean anything special:
  445.    multicasts can be used on all not-NBMA links.
  446.    IFF_MULTICAST means that this media uses special encapsulation
  447.    for multicast frames. Apparently, all IFF_POINTOPOINT and
  448.    IFF_BROADCAST devices are able to use multicasts too.
  449.  */
  450.  
  451. /* ifi_link.
  452.    For usual devices it is equal ifi_index.
  453.    If it is a "virtual interface" (f.e. tunnel), ifi_link
  454.    can point to real physical interface (f.e. for bandwidth calculations),
  455.    or maybe 0, what means, that real media is unknown (usual
  456.    for IPIP tunnels, when route to endpoint is allowed to change)
  457.  */
  458.  
  459. /*****************************************************************
  460.  *        Traffic control messages.
  461.  ****/
  462.  
  463. struct tcmsg
  464. {
  465.     unsigned char    tcm_family;
  466.     unsigned char    tcm__pad1;
  467.     unsigned short    tcm__pad2;
  468.     int        tcm_ifindex;
  469.     __u32        tcm_handle;
  470.     __u32        tcm_parent;
  471.     __u32        tcm_info;
  472. };
  473.  
  474. enum
  475. {
  476.     TCA_UNSPEC,
  477.     TCA_KIND,
  478.     TCA_OPTIONS,
  479.     TCA_STATS,
  480.     TCA_XSTATS,
  481.     TCA_RATE,
  482. };
  483.  
  484. #define TCA_MAX TCA_RATE
  485.  
  486. #define TCA_RTA(r)  ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
  487. #define TCA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcmsg))
  488.  
  489.  
  490. /* SUMMARY: maximal rtattr understood by kernel */
  491.  
  492. #define RTATTR_MAX        RTA_MAX
  493.  
  494. /* RTnetlink multicast groups */
  495.  
  496. #define RTMGRP_LINK        1
  497. #define RTMGRP_NOTIFY        2
  498. #define RTMGRP_NEIGH        4
  499. #define RTMGRP_TC        8
  500.  
  501. #define RTMGRP_IPV4_IFADDR    0x10
  502. #define RTMGRP_IPV4_MROUTE    0x20
  503. #define RTMGRP_IPV4_ROUTE    0x40
  504.  
  505. #define RTMGRP_IPV6_IFADDR    0x100
  506. #define RTMGRP_IPV6_MROUTE    0x200
  507. #define RTMGRP_IPV6_ROUTE    0x400
  508.  
  509. /* End of information exported to user level */
  510.  
  511. #ifdef __KERNEL__
  512.  
  513. extern atomic_t rtnl_rlockct;
  514. extern struct wait_queue *rtnl_wait;
  515.  
  516. extern __inline__ int rtattr_strcmp(struct rtattr *rta, char *str)
  517. {
  518.     int len = strlen(str) + 1;
  519.     return len > rta->rta_len || memcmp(RTA_DATA(rta), str, len);
  520. }
  521.  
  522. extern int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len);
  523.  
  524. #ifdef CONFIG_RTNETLINK
  525. extern struct sock *rtnl;
  526.  
  527. struct rtnetlink_link
  528. {
  529.     int (*doit)(struct sk_buff *, struct nlmsghdr*, void *attr);
  530.     int (*dumpit)(struct sk_buff *, struct netlink_callback *cb);
  531. };
  532.  
  533. extern struct rtnetlink_link * rtnetlink_links[NPROTO];
  534. extern int rtnetlink_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb);
  535. extern int rtnetlink_send(struct sk_buff *skb, u32 pid, u32 group, int echo);
  536.  
  537. extern void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data);
  538.  
  539. #define RTA_PUT(skb, attrtype, attrlen, data) \
  540. ({ if (skb_tailroom(skb) < (int)RTA_SPACE(attrlen)) goto rtattr_failure; \
  541.    __rta_fill(skb, attrtype, attrlen, data); })
  542.  
  543. extern unsigned long rtnl_wlockct;
  544.  
  545. /* NOTE: these locks are not interrupt safe, are not SMP safe,
  546.  * they are even not atomic. 8)8)8) ... and it is not a bug.
  547.  * Really, if these locks will be programmed correctly,
  548.  * all the addressing/routing machine would become SMP safe,
  549.  * but is absolutely useless at the moment, because all the kernel
  550.  * is not reenterable in any case. --ANK
  551.  *
  552.  * Well, atomic_* and set_bit provide the only thing here:
  553.  * gcc is confused not to overoptimize them, that's all.
  554.  * I remember as gcc splitted ++ operation, but cannot reproduce
  555.  * it with gcc-2.7.*. --ANK
  556.  *
  557.  * One more note: rwlock facility should be written and put
  558.  * to a kernel wide location: f.e. current implementation of semaphores
  559.  * (especially, for x86) looks like a wonder. It would be good
  560.  * to have something similar for rwlock. Recursive lock could be also
  561.  * useful thing. --ANK
  562.  */
  563.  
  564. extern __inline__ int rtnl_shlock_nowait(void)
  565. {
  566.     atomic_inc(&rtnl_rlockct);
  567.     if (test_bit(0, &rtnl_wlockct)) {
  568.         atomic_dec(&rtnl_rlockct);
  569.         return -EAGAIN;
  570.     }
  571.     return 0;
  572. }
  573.  
  574. extern __inline__ void rtnl_shlock(void)
  575. {
  576.     while (rtnl_shlock_nowait())
  577.         sleep_on(&rtnl_wait);
  578. }
  579.  
  580. /* Check for possibility to PROMOTE shared lock to exclusive.
  581.    Shared lock must be already grabbed with rtnl_shlock*().
  582.  */
  583.  
  584. extern __inline__ int rtnl_exlock_nowait(void)
  585. {
  586.     if (atomic_read(&rtnl_rlockct) > 1)
  587.         return -EAGAIN;
  588.     if (test_and_set_bit(0, &rtnl_wlockct))
  589.         return -EAGAIN;
  590.     return 0;
  591. }
  592.  
  593. extern __inline__ void rtnl_exlock(void)
  594. {
  595.     while (rtnl_exlock_nowait())
  596.         sleep_on(&rtnl_wait);
  597. }
  598.  
  599. #if 0
  600. extern __inline__ void rtnl_shunlock(void)
  601. {
  602.     atomic_dec(&rtnl_rlockct);
  603.     if (atomic_read(&rtnl_rlockct) <= 1) {
  604.         wake_up(&rtnl_wait);
  605.         if (rtnl && rtnl->receive_queue.qlen)
  606.             rtnl->data_ready(rtnl, 0);
  607.     }
  608. }
  609. #else
  610.  
  611. /* The problem: inline requires to include <net/sock.h> and, hence,
  612.    almost all of net includes :-(
  613.  */
  614.  
  615. #define rtnl_shunlock() ({ \
  616.     atomic_dec(&rtnl_rlockct); \
  617.     if (atomic_read(&rtnl_rlockct) <= 1) { \
  618.         wake_up(&rtnl_wait); \
  619.         if (rtnl && rtnl->receive_queue.qlen) \
  620.             rtnl->data_ready(rtnl, 0); \
  621.     } \
  622. })
  623. #endif
  624.  
  625. /* Release exclusive lock. Note, that we do not wake up rtnetlink socket,
  626.  * it will be done later after releasing shared lock.
  627.  */
  628.  
  629. extern __inline__ void rtnl_exunlock(void)
  630. {
  631.     clear_bit(0, &rtnl_wlockct);
  632.     wake_up(&rtnl_wait);
  633. }
  634.  
  635. #else
  636.  
  637. extern __inline__ void rtnl_shlock(void)
  638. {
  639.     while (atomic_read(&rtnl_rlockct))
  640.         sleep_on(&rtnl_wait);
  641.     atomic_inc(&rtnl_rlockct);
  642. }
  643.  
  644. extern __inline__ void rtnl_shunlock(void)
  645. {
  646.     if (atomic_dec_and_test(&rtnl_rlockct))
  647.         wake_up(&rtnl_wait);
  648. }
  649.  
  650. extern __inline__ void rtnl_exlock(void)
  651. {
  652. }
  653.  
  654. extern __inline__ void rtnl_exunlock(void)
  655. {
  656. }
  657.  
  658. #endif
  659.  
  660. extern void rtnl_lock(void);
  661. extern void rtnl_unlock(void);
  662. extern void rtnetlink_init(void);
  663.  
  664. #endif /* __KERNEL__ */
  665.  
  666.  
  667. #endif    /* __LINUX_RTNETLINK_H */
  668.